/* 
 * Copyright 2011 VelocitiSoftware
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.velociti.ikarus.widget.client.ui;

import java.util.Date;
import java.util.Iterator;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.WidgetCollection;
import com.vaadin.terminal.gwt.client.ui.VPopupCalendar;

/**
 * ######VIkarusDateField##### -Access to the inner components. -Attach/detach
 * component at client side.
 * 
 * @author Alper Turkyilmaz - VelocitiSoftware - 2011
 * @version 1.0.2
 * 
 */
public class VIkarusDateField extends VPopupCalendar implements IVClientSideAttachDetach {
	private Button button;
	private TextBox text;

	public VIkarusDateField() {
		super();
		WidgetCollection coll = getChildren();
		for (Iterator iterator = coll.iterator(); iterator.hasNext();) {
			Widget widget = (Widget) iterator.next();
			if (widget.getElement().equals(getSubPartElement("popupButton"))) {
				button = (Button) widget;
			} else if (widget.getElement().equals(getSubPartElement("field"))) {
				text = (TextBox) widget;
			}
		}
	}

	public String getText() {
		return super.getText();
	}

	public void attach() {
		onAttach();
		RootPanel.detachOnWindowClose(this);
	}

	public void detach() {
		onDetach();
	}

	public void setCurrentDate(Date date) {
		super.setCurrentDate(date);
		buildDate();
	}

	public TextBox getTextBox() {
		return text;
	}

	public Button getButton() {
		return button;
	}

	public String getFormatString() {
		return super.getFormatString();
	}
}
